<!--
 * @Description: 
 * @Author: shizhe
 * @Date: 2022-03-08 14:02:21
 * @LastEditTime: 2022-03-25 16:02:08
 * @LastEditors: shizhe
 * @Reference: 
-->
<template>
  <div id="account">
    <div class="search-con">
      <el-select v-model="contractId" filterable placeholder="请选择" size="small" @change="contractChange">
        <el-option v-for="item in conOptions" :key="item.value" :label="item.numberAndName" :value="item.id">
        </el-option>
      </el-select>
      <div class="exhibit text_hidde">{{ contractContent || '--' }}</div>
      <div style="margin-left: 20px; width: 150px" class="text_hidde">创建人：{{ createBy || '--' }}</div>
    </div>
    <div class="search-con">
      <label style="margin-right: 30px">合同形式：{{ contractForm }}</label>
      <label style="margin-right: 30px">合同保证金：{{ margin }}/{{ margin }}万元</label>
      <label>结算进度：{{ acceptedAmount }}/{{ contractAmount }}万元</label>
      <el-progress
        :percentage="percentage"
        color="#30C776"
        :stroke-width="6"
        style="width: 150px; margin-left: 20px"
        :format="progressFormat"
      ></el-progress>
    </div>

    <div class="list-container">
      <el-table
        :data="tableData"
        class="table"
        height="100%"
        ref="jdjgTable"
        @sort-change="sortChange"
        :header-cell-style="{
          padding: '0px',
          background: 'linear-gradient(0deg, #F4F6F9, #EAECF4, #F3F6F9)'
        }"
        :row-class-name="tabRowClassName"
        header-row-class-name="mapTable_th"
      >
        <el-table-column width="60" align="center" type="index" :index="addIndex" label="序号">
          <el-table-column width="60" align="center" type="index" label="检索"> </el-table-column>
        </el-table-column>
        <el-table-column label="流水号" align="center">
          <el-table-column align="center" sortable="custom" prop="bankTradeCode" width="160">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="付款账户" align="center">
          <el-table-column align="center" sortable="custom" prop="tradeAccountCode" width="180">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="付款人" align="center">
          <el-table-column align="center" sortable="custom" prop="tradeAccountName" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="收款账户" align="center">
          <el-table-column align="center" sortable="custom" prop="bankAccountCode" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="金额" align="center">
          <el-table-column align="center" sortable="custom" prop="tradeAmount" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="到账状态" align="center">
          <el-table-column align="center" width="180">
            <template slot-scope="{}">
              <div>已到账</div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="到账时间" align="center" width="150" fixed="right">
          <el-table-column align="center" sortable="custom" prop="tradeDate" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.tradeDate }}{{ scope.row.tradetime }}</div>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ruzhang',
  data() {
    return {
      searchQrcoUsed: '',
      contractForm: '',
      contractId: '',
      conOptions: [],
      percentage: 0,
      percentageTo: 0,
      contractContent: '',
      margin: '',
      acceptedAmount: null,
      contractAmount: null,
      createBy: '',
      tableData: []
    }
  },
  mounted() {
    this.getSelectOption()
  },
  methods: {
    progressFormat(val) {
      if (this.percentageTo >= 100) {
        return `${this.percentageTo}%`
      } else {
        return `${val}%`
      }
    },
    // 获取合同下拉
    getSelectOption(id) {
      this.$https({
        method: 'post',
        url: '/contract/queryContractProNameList'
      })
        .then(res => {
          if (res.code == 0) {
            this.conOptions = res.data
            if (id) {
              this.contractId = id
              this.conOptions.forEach(item => {
                if (id == item.id) {
                  this.createBy = item.createBy
                  this.contractContent = item.biddingContent
                  let obj = {
                    1: '固定总价',
                    2: '固定单价',
                    3: '可调总价',
                    4: '可调单价',
                    5: '用户自定义'
                  }
                  this.contractForm = obj[item.contractForm]
                  this.margin = item.margin

                  this.acceptedAmount = item.acceptedAmount || 0
                  this.contractAmount = item.contractAmount
                  this.percentage = Math.round((this.acceptedAmount / this.contractAmount) * 100)
                  if (this.percentage > 100) {
                    this.percentage = 100
                  }
                  this.percentageTo = Math.round((this.acceptedAmount / this.contractAmount) * 100)
                  obj = null
                }
              })
            } else {
              this.contractId = this.conOptions[0].id
              this.createBy = this.conOptions[0].createBy
              this.contractContent = this.conOptions[0].biddingContent
              let obj = {
                1: '固定总价',
                2: '固定单价',
                3: '可调总价',
                4: '可调单价',
                5: '用户自定义'
              }
              this.contractForm = obj[this.conOptions[0].contractForm]
              this.margin = this.conOptions[0].margin

              this.acceptedAmount = this.conOptions[0].acceptedAmount || 0
              this.contractAmount = this.conOptions[0].contractAmount
              this.percentage = Math.round((this.acceptedAmount / this.contractAmount) * 100)
              if (this.percentage > 100) {
                this.percentage = 100
              }
              this.percentageTo = Math.round((this.acceptedAmount / this.contractAmount) * 100)
              obj = null
              this.getData()
            }
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    getData() {
      this.$https({
        method: 'post',
        url: '/payOfSettlement/payRecordByConId?contractId=' + this.contractId
      })
        .then(res => {
          if (res.code == 0) {
            this.tableData = res.data
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    contractChange(id) {
      this.conOptions.forEach(item => {
        if (id == item.id) {
          this.createBy = item.createBy
          this.contractContent = item.biddingContent
          let obj = {
            1: '固定总价',
            2: '固定单价',
            3: '可调总价',
            4: '可调单价',
            5: '用户自定义'
          }
          this.contractForm = obj[item.contractForm]
          this.margin = item.margin

          this.acceptedAmount = item.acceptedAmount || 0
          this.contractAmount = item.contractAmount
          this.percentage = Math.round((this.acceptedAmount / this.contractAmount) * 100)
          if (this.percentage > 100) {
            this.percentage = 100
          }
          this.percentageTo = Math.round((this.acceptedAmount / this.contractAmount) * 100)
          obj = null
        }
      })
      this.getData()
    },
    getDataChange() {},
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.page - 1) * this.size
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  }
}
</script>
<style lang="less" scoped>
#account {
  height: calc(100% - 56px);
  padding: 16px 16px 40px 16px;
  .list-container {
    height: calc(100vh - 220px);
  }
  .sc,
  .ty {
    color: #ff3d3d;
  }
  .add {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    width: 114px;
  }
  .search-con {
    color: #333;
    display: flex;
    margin-bottom: 20px;
    align-items: center;
    font-size: 14px;
    font-weight: 400px;
    /deep/.el-select {
      width: 500px;
    }
  }
  .exhibit {
    font-weight: 500;
    margin-left: 20px;
    padding-right: 20px;
    border-right: 1px solid #999;
    max-width: 210px;
  }
}
</style>
